package com.shujia.profile.behavior.order

import com.shujia.profile.UserProfile
import com.shujia.util.SparkUtil
import org.apache.spark.sql.{DataFrame, SparkSession}

class UserProfileOrderTime extends UserProfile{
  flagName = "orderTime"

  /**
   * 用于提取用户画像的接口
   *
   * @param spark ： spark环境
   * @return
   */
  override def extractProfile(spark: SparkSession): DataFrame = {

    spark.sql(
      s"""
         |select
         |member_id as id,
         |max(create_time) as orderTime
         |FROM
         |dwd.dwd_t_order_d_f
         |where ds='$ds'
         |GROUP BY member_id
         |
         |""".stripMargin)

  }
}

object UserProfileOrderTime {
  def main(args: Array[String]): Unit = {
    //获取参数,在提交任务时，在包名后面增加的参数
    val ds: String = args.head
    //spark环境
    val spark: SparkSession = SparkUtil.getSession()

    new UserProfileOrderTime().run(spark, ds)
  }
}
